package com.gexiaobao.pigeon.ui.adapter

import android.annotation.SuppressLint
import androidx.appcompat.widget.AppCompatImageView
import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.gexiaobao.pigeon.R
import com.gexiaobao.pigeon.app.model.bean.MessageListResponse

/**
 * @author:hxw
 * @date  :2023/1/16
 * @desc  :
 */
class MessageAllListAdapter(data: ArrayList<MessageListResponse.DataList>) :
    BaseQuickAdapter<MessageListResponse.DataList, BaseViewHolder>(R.layout.item_all_message_list, data) {

    @SuppressLint("CheckResult")
    override fun convert(holder: BaseViewHolder, item: MessageListResponse.DataList) {
        holder.setText(R.id.tv_item_message_list_type, item.topic)
        holder.setText(R.id.tv_item_message_list_time, item.createdAt)

        val messageIcon = holder.getView<AppCompatImageView>(R.id.mine_message_list_icon)

        var resId = R.mipmap.bisai_wodexiaoxi_my_
        when (item.messageType) {
            1 -> {
                resId = if (item.read == 1) {
                    R.mipmap.my_notice_icon_read
                } else {
                    R.mipmap.mine_message_notify
                }

            }
            3 -> {
                resId = if (item.read == 1) {
                    R.mipmap.bisai1_wodexiaoxi_my_
                } else {
                    R.mipmap.bisai_wodexiaoxi_my_
                }
            }
            0 -> {
                resId = if (item.read == 1) {
                    R.mipmap.mine_message_join_out
                } else {
                    R.mipmap.mine_message_join_in
                }
            }
        }
        val requestOptions = RequestOptions()
        requestOptions.placeholder(R.mipmap.profilepic_str_1)
            .error(R.mipmap.profilepic_str_1)
            .fitCenter()
            .dontAnimate()//防止设置placeholder导致第一次不显示网络图片,只显示默认图片的问题

        Glide.with(context)
            .load(resId)
            .apply(requestOptions)
            .into(messageIcon)
    }
}